subroutine set_space_vectors(ExFilter, xMod, uPerpMod)

  use dimensions
  use fft_wrap,   only  : fft_forward, fft_backward

  use parameters, only : kz, nz, Lx, vPhase, Vmax,  SpeckleWidth,  &
                         KxFilter, iWaveFrame, iBcPerpPeriodic, pi

  implicit none

  real,    intent(out) :: ExFilter(jx)
  complex, intent(out) :: xMod(jx), uPerpMod(jx)

  integer              :: ix, iz, iv       ! counters in r-space
  integer              :: ikx, ikz, ip     ! counters in k-space


      !--  setting spectral resolution --

      dkz = kz/nz
      dkx = 2*pi / Lx
      

      !-- spatial resolution --

      if (iBcPerpPeriodic.EQ.1) then
         dx = Lx/jx
      else
         dx = Lx/(jx-1)
      endif

      dz = 2*pi/(jz*dkz)       



      !-- dimension vectors in r-space --

      do ix=1,jx
         xvec(ix) = -Lx/2 + dx * (ix-1)
      enddo

      do iz=1,jz
         zvec(iz) = (iz-1)*dz
      enddo    

      do iv=1,jv
         vvec(iv)=-vPhase*iWaveFrame -Vmax + ((iv-1)/(jv-1.0))*2*Vmax
      end do
      
      dv=( vvec(jv)-vvec(1) )/(jv-1)
      !dv = 2*Vmax/(jv-1)



      !-- dimension vectors in k-space --

      nkz=jz; nkx = jx; np=jv


      kXvec(1)=1.0E-10      !	don't want to divide by zero later 
      do ikx=2,jx/2
         kXvec(ikx)=kXvec(ikx-1)+dkx
      end do
      kXvec(jx)=-dkx
      do ikx=jx-1,jx/2+1,-1
         kXvec(ikx)=kXvec(ikx+1)-dkx
      end do


      kZvec(1)=1.0E-10      !	don't want to divide by zero later
      do ikz=2,nkz/2
         kZvec(ikz)=kZvec(ikz-1)+dkz
      end do
      kZvec(nkz)=-dkz
      do ikz=nkz-1,nkz/2+1,-1
         kZvec(ikz)=kZvec(ikz+1)-dkz
      end do


      dp=2*pi/(jv*dv)
      pvec(1)=0.0
      do ip=2,jv/2
         pvec(ip)=pvec(ip-1)+dp
      end do
      pvec(jv)=-dp
      do ip=jv-1,jv/2+1,-1
         pvec(ip)=pvec(ip+1)-dp
      end do


      !-- setting KxFilter  --

      ExFilter=1.0
      do ikx=1,jx
         if( abs(kXvec(ikx)) > KxFilter ) ExFilter(ikx) = 0
      enddo


      !-- setting modulation vectors --

      xMod(:)     = exp( - 20 * xvec(:)**2 / SpeckleWidth**2 )   !  complex xMod(jx)
      uPerpMod(:) = exp( - 14 * xvec(:)**6 / (Lx/2)**6 )         !  complex uPerpMod(jx)
 
      call fft_forward(jx,xMod,xMod)
      xMod=xMod/float(jx)
      call deAlias(jx,xMod)
      call fft_backward(jx,xMod,xMod)  
 
      call fft_forward(jx,uPerpMod,uPerpMod)
      uPerpMod=uPerpMod/float(jx)
      call deAlias(jx,uPerpMod)        
      call fft_backward(jx,uPerpMod,uPerpMod)
        

end subroutine set_space_vectors

!-------------------------------------------------------------------------------------
